﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>收入汇总</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script> 
<script type="text/javascript" src="../js/find.js"></script>
<script type="text/javascript" src="../js/qmsk-1.0.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" >
/**
 * 入口，和服务器的通信从此开始
 */
$(function() {
	refreshInput($(".serWrapper"));
	initShopSelecter();
	$('.doubledate').kuiDate({
		className : 'doubledate',
		isDisabled : "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	$('.doubledate1').kuiDate({
		className : 'doubledate1',
		isDisabled : "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	
	initSchuTypecheck();
	initSchuType();
	

});

function shopSelected(shopId, shopName){
	initSchuType();
}


function initSchuTypecheck(){
	$("#goodsTypeIsChoosed").removeAttr("checked");
	$("#stId").attr("disabled", "disabled");
	$("#goodsTypeIsChoosed").bind("click", function() {
		var checked = $(this).attr("checked");
		if (checked) {
			$("#stId").removeAttr("disabled");
		} else {
			$("#stId").attr("disabled", "disabled");
			$("#stId").empty();
		}
	});
}

function initSchuType(){
	var shopId = $('#shopID').val();
	qmsk.initSelect({
		url : '../scheduleType/find/bussBill',
		id : 'stId',
		data : {"shopId":shopId},
		heads : ['ID', 'Name'],
		defaults : {
			key : '请选择业务类型',
			value : ' '
		}
	});
}

/**
 * 为查找做准备，这里主要是生成查询条件对象
 */
function toSearch() {
	$("#incomeTotal").empty();
	$("#sum").empty();
	var shopId = $('#shopID').val();
	var dtPaidStart = $('#dtPaidStart').val();
	var dtPaidEnd = $('#dtPaidEnd').val();
	var stId = $('#stId').val();
	new Pagination({
		url : '../incomeTotal/find/total',
		data : {
			shopId : shopId,
			dtPaidStart : dtPaidStart,
			dtPaidEnd : dtPaidEnd,
			stId : stId
		},
		success : printDataToPage,
		pageSize : 10
	});
	
	if(IsNotEmpty(shopId)){
		initSchuType();
	}
}



function printDataToPage(message){
	var oldBillNo = null;
	dataTable({
		tbodyId : 'incomeTotal',
		heads : ["stName", "nums", "ReceAmt", "FactAmt", "PayDepstAmt", "PayIntAmt",  "PayDisctCoup", "PayCashCoupAmtMny", "PayCash","PayPos", "PayCheck"],
		rst : message,
		sup : {
			id : "sup",
			template : "共 [index] 条"
		}
	});
	
	findGoodsTypeSum();
}

/**
 * 累计消费总和
 */
function findGoodsTypeSum(){
	var shopId = $('#shopID').val();
	var dtPaidStart = $('#dtPaidStart').val();
	var dtPaidEnd = $('#dtPaidEnd').val();
	var stId = $('#stId').val();
	/* 	new Pagination({
		url : '../incomeTotal/find/total/sum',
		data : {
			shopId : shopId,
			dtPaidStart : dtPaidStart,
			dtPaidEnd : dtPaidEnd,
			stId : stId,
			billNo : billNo
		},
		success : printDataToPageSum,
		pageSize : 10
	}); */
 	var rst = _findInfo("../incomeTotal/find/total/sum",{
		"shopId" : shopId,
		"dtPaidStart" : dtPaidStart,
		"dtPaidEnd" : dtPaidEnd,
		"stId" : stId
	});
	
	if(IsNotEmpty(rst)){
		var htmlStr = "合计:"
		var htmlGD = "&nbsp&nbsp&nbsp";
		var sum = 0;
		var oldsum = 0;

		var factAmt = getHtmlInt(getHeadIndexValue(0,rst,'FactAmt'));
		if(factAmt > 0){
			sum = sum+factAmt;
			htmlStr += "实收款:"+factAmt;
			oldsum = sum;
		}
		
		var receAmt = getHtmlInt(getHeadIndexValue(0,rst,'ReceAmt'));
		if(receAmt > 0){
			sum = sum+receAmt;
			if(oldsum < sum && oldsum != 0){
				htmlStr += htmlGD;
			}
			htmlStr += "应收款:"+receAmt;
			oldsum = sum;
		}
		
		var payDepstAmt = getHtmlInt(getHeadIndexValue(0,rst,'PayDepstAmt'));
		if(payDepstAmt > 0){
			sum = sum+payDepstAmt;
			if(oldsum < sum && oldsum != 0){
				htmlStr += htmlGD;
			}
			htmlStr += "预存支付:"+payDepstAmt;
			oldsum = sum;
		}
		
		var payCash = getHtmlInt(getHeadIndexValue(0,rst,'PayCash'));
		if(payCash > 0){
			sum = sum+payCash;
			if(oldsum < sum && oldsum != 0){
				htmlStr += htmlGD;
			}
			htmlStr += "现金支付:"+payCash;
			oldsum = sum;
		}
		var payDisctCoup = getHtmlInt(getHeadIndexValue(0,rst,'PayDisctCoup'));
		if(payDisctCoup > 0){
			sum = sum+payDisctCoup;
			if(oldsum < sum && oldsum != 0){
				htmlStr += htmlGD;
			}
			htmlStr += "代金券支付:"+payDisctCoup;
			oldsum = sum;
		}
		var payCashCoupAmtMny = getHtmlInt(getHeadIndexValue(0,rst,'PayCashCoupAmtMny'));
		if(payCashCoupAmtMny > 0){
			sum = sum+payCashCoupAmtMny;
			if(oldsum < sum && oldsum != 0){
				htmlStr += htmlGD;
			}
			htmlStr += "优惠券支付:"+payCashCoupAmtMny;
			oldsum = sum;
		}
		
		var payIntAmtMny = getHtmlInt(getHeadIndexValue(0,rst,'PayIntAmtMny'));
		if(payIntAmtMny > 0){
			sum = sum+payIntAmtMny;
			if(oldsum < sum && oldsum != 0){
				htmlStr += htmlGD;
			}
			htmlStr += "积分支付:"+payIntAmtMny;
			oldsum = sum;
		}
		
		var payPos = getHtmlInt(getHeadIndexValue(0,rst,'PayPos'));
		if(payPos > 0){
			sum = sum+payPos;
			if(oldsum < sum && oldsum != 0){
				htmlStr += htmlGD;
			}
			htmlStr += "POS支付:"+payPos;
			oldsum = sum;
		}
		
		var payCheck = getHtmlInt(getHeadIndexValue(0,rst,'PayCheck'));
		if(payCheck > 0){
			sum = sum+payCheck;
			if(oldsum < sum && oldsum != 0){
				htmlStr += htmlGD;
			}
			htmlStr += "支票支付:"+payCheck;
			oldsum = sum;
		}
		if(sum > 0){
			$("#sum").html(htmlStr);
		}else{
			$("#sum").html("");
		}
	}
}


/**
 * 初始化店面选择器
 */
function initShopSelecter() {
	refreshInput($(".serWrapper"));
	$("#shopID").attr("disabled", "disabled");

	$("#shopIsChoosed").bind("click", function() {
		var checked = $(this).attr("checked");
		if (checked) {
			$("#shopID").removeAttr("disabled");
		} else {
			$("#shopID").attr("disabled", "disabled");
			$("#shopID").empty();
		}
	});
}

function downRescouse(){
	var shopId = $('#shopID').val();
	var dtPaidStart = $('#dtPaidStart').val();
	var dtPaidEnd = $('#dtPaidEnd').val();
	var stId = $('#stId').val();
	var param = {'shopId':shopId,'dtPaidStart':dtPaidStart,'dtPaidEnd':dtPaidEnd,'stId':stId}
	window.location.href='../incomeTotal/find/export/csv?'+$.param(param)
	
}

</script>
</head>

<body>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">收入汇总</div>
    <div class="member_search">
      <p><span>
        <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">
        店面：</span>
 		<select id="shopID"  class="shopName" onclick="openShopListPanel(this)" style="height: 20px;"></select>
        <span>起始日期：</span>
        <input type="text" readonly class="doubledate ipticon"  id="dtPaidStart"/>
        <span>截止时间：</span>
        <input type="text" readonly class="doubledate1 ipticon" id="dtPaidEnd"/>
      </p>
      <p>
        <span><input type="checkbox" id="goodsTypeIsChoosed" style="width:auto;height:auto;border:none;">商品类型：</span>
       	<select id="stId"  class="shopName"  style="height: 20px;"></select>
      <input type="button" value="查询" class="btn" onclick="toSearch()">
      </p>
    </div>
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
      <caption>
      <strong>收入汇总列表 <span id="sup">共0条</span></strong> <a href="javascript:void(0)" onclick="downRescouse()">导出数据</a>
      </caption>
      <thead>
        <tr>
          <th>业务类型</th>
          <th>单据数</th>
          <th>应收款</th>
          <th>实收款</th>
          <th>预存支付</th>
          <th>积分支付</th>
          <th>代金券支付</th>
          <th>优惠券支付</th>
          <th>现金支付</th>
          <th>POS支付</th>
          <th>支票支付</th>
        </tr>
      </thead>
      <tbody id="incomeTotal">
      
      </tbody>
    </table>
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="sum" style="float: left;"></div>
    <div id="pager" class="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
</script>
</body>
<!-- InstanceEnd -->
</html>
